/**
 * @param {Object} initConfig 地图对象定义
 */
function LayerCreator(config) {
  this._init_(config);
}

LayerCreator.prototype = {
  constructor: LayerCreator,
  _init_: function () {
  },
  guid: function () {
      return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
          var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
          return v.toString(16);
      });
  },
  createLayer: function (config) {
      var layer = null;
      var uuid = this.guid();
      if (config.bklayerType.toLowerCase() == "vectorlayer_empty") {
          config.bklayerType = "vectorlayer";
          layer = new ol.layer.Vector({
              source: new ol.source.Vector({ wrapX: false }),
              visible: config.visible,
              declutter: config.declutter
          });
      } else if (config.bklayerType.toLowerCase() == "vectorlayer_test") {
          config.bklayerType = "vectorlayer";
          layer = new ol.layer.Vector({
              source: new ol.source.Vector({ wrapX: false }),
              visible: config.visible
          });
          // const style = new ol.style.Style({
          //     fill: new ol.style.Fill({
          //         color: '#eeeeee',
          //     }),
          // })
          // layer = new ol.layer.Vector({
          //     source: new ol.source.Vector({
          //         url: 'https://openlayers.org/data/vector/ecoregions.json',
          //         format: new ol.format.GeoJSON(),
          //     }),
          //     background: 'white',
          //     style: function (feature) {
          //         const color = feature.get('COLOR') || '#eeeeee';
          //         style.getFill().setColor(color);
          //         return style;
          //     },
          // });
      } else if (config.bklayerType.toLowerCase() == "vectorlayer") {
          layer = new ol.layer.Vector({
              source: new ol.source.Vector({ wrapX: false }),
              style: function (f) {
                  var style;
                  if (f.get("bklayerStyleObject") != null && f.get("bklayerStyleFunction") != null) {
                      style = f.get("bklayerStyleObject")[f.get("bklayerStyleFunction")](f);
                  }
                  return style;
              },
              visible: config.visible
          });
      } else if (config.bklayerType.toLowerCase() == "celiangvectorlayer") {
          layer = new ol.layer.Vector({
              source: new ol.source.Vector({ wrapX: false }),
              style: new ol.style.Style({
                  fill: new ol.style.Fill({
                      color: 'rgba(255, 0, 0, 0.2)'
                  }),
                  stroke: new ol.style.Stroke({
                      color: '#f00',
                      width: 3
                  }),
                  image: new ol.style.RegularShape({ radius: 5, points: 4, angle: Math.PI / 4, fill: new ol.style.Fill({ color: '#FF0000' }) })
              }),
              visible: config.visible
          });
      } else if (config.bklayerType.toLowerCase() == "zdjyborderlayer") {
          layer = new ol.layer.Vector({
              source: new ol.source.Vector({ wrapX: false }),
              style: function (f) {
                  return [
                      new ol.style.Style({
                          stroke: new ol.style.Stroke({ color: '#FF66FF', width: 3 })
                      }),
                      new ol.style.Style({
                          image: new ol.style.RegularShape({ radius: 5, points: 4, angle: Math.PI / 4, fill: new ol.style.Fill({ color: '#FF6600' }) }),
                          geometry: new ol.geom.MultiPoint(f.getGeometry().getCoordinates()[0])
                      })
                  ]
              },
              visible: config.visible
          });
      } else if (config.bklayerType.toLowerCase() == "jietuvectorlayer") {
          config.bklayerType = "vectorlayer";
          layer = new ol.layer.Vector({
              source: new ol.source.Vector({ wrapX: false }),
              style: new ol.style.Style({
                  stroke: new ol.style.Stroke({
                      color: '#0ff',
                      width: 2
                  })
              }),
              visible: config.visible
          });
      } else if (config.bklayerType.toLowerCase() == "zhezhaovectorlayer") {
          config.bklayerType = "vectorlayer";
          var mystyle = new ol.style.Style({
              fill: new ol.style.Fill({
                  color: "rgba(33,33,33, 0.5)"
              }),
              stroke: new ol.style.Stroke({
                  color: "#BDBDBD",
                  width: 2
              })
          });
          layer = new ol.layer.Vector({
              source: new ol.source.Vector({ wrapX: false }),
              style: mystyle,
              visible: config.visible
          });
      } else if (config.bklayerType.toLowerCase() == "drawvectorlayer") {
          function styleFunction(feature) {
              var styles = [];
              styles.push(new ol.style.Style({
                  stroke: new ol.style.Stroke({
                      color: "#ff0000",
                      width: 2
                  }), image: new ol.style.Circle({
                      radius: 4,
                      fill: new ol.style.Fill({
                          color: '#ffff'
                      }),
                      stroke: new ol.style.Stroke({
                          color: '#ff0000',
                          width: 2
                      })
                  })
              }))
              styles.push(
                  new ol.style.Style({
                      geometry: function (feature) {
                          var coordinates = feature.getGeometry().getCoordinates();
                          return new ol.geom.MultiPoint(coordinates);
                      }, image: new ol.style.Circle({
                          radius: 4,
                          fill: new ol.style.Fill({
                              color: '#ffff'
                          }),
                          stroke: new ol.style.Stroke({
                              color: '#ff0000',
                              width: 2
                          })
                      })
                  })
              );
              //console.log(styles.length);
              return styles;
          }
          config.bklayerType = "vectorlayer";
          layer = new ol.layer.Vector({
              source: new ol.source.Vector({ wrapX: false }),
              style: styleFunction,
              visible: config.visible
          });
          /*  function (feature) {
                return [
                    new ol.style.Style({
                        image: new ol.style.Circle({
                            radius: 5,
                            fill: new ol.style.Fill({
                                color: 'rgba(253, 251, 152, 0)'
                            }),
                            stroke: new ol.style.Stroke({color: 'rgba(0, 204, 0, 1)', width: 3})
                        }),
                        geometry: function(feature) {
                            var coordinates;
                            if (feature.getGeometry().getType() == "LineString"){
                                coordinates = feature.getGeometry().getCoordinates();
                            } else if (feature.getGeometry().getType() == "Polygon"){
                                coordinates = feature.getGeometry().getCoordinates()[0];
                            } else if (feature.getGeometry().getType() == "MultiLineString"){
                                coordinates = feature.getGeometry().getCoordinates()[0];
                            }  else if (feature.getGeometry().getType() == "MultiPoint"){
                                coordinates = feature.getGeometry().getCoordinates();
                            } else if (feature.getGeometry().getType() == "Point"){
                                //not 100% sure this would work!!!!
                                coordinates = [feature.getGeometry().getCoordinates()];
                            }else if (feature.getGeometry().getType() == "Circle"){
                                return "";
                            } else if (feature.getGeometry().getType() == "MultiPolygon"){
                                var cds = feature.getGeometry().getCoordinates();
                                var cds_arr = [];
                                for(var i =0;i<cds.length;i++){
                                    var p = cds[i];
                                    for(var n=0;n<p.length;n++){
                                        var np = p[n];
                                        for(var t = 0;t<np.length;t++){
                                            cds_arr.push(np[t]);
                                        }
                                    }
                                }
                                return new ol.geom.MultiPoint(cds_arr);
                            } else {
                                console.log('maybe you need to handle also multi geometries!','','确定',function (e) {},'div')
                            }
                            return new ol.geom.MultiPoint(coordinates);
                        }
                    }),
                    new ol.style.Style({
                        stroke: new ol.style.Stroke({
                            color: "#00aaff",
                            width: 2
                        }),
                        fill: new ol.style.Fill({
                            color: "rgba(255,255,255,0.3)"
                        })
                    })
                ]
            }*/
      } else if (config.bklayerType.toLowerCase() == "clusterlayer") {
          layer = new ol.layer.Vector({
              source: new ol.source.Cluster({
                  distance: config.distance,
                  source: new ol.source.Vector()
              }),
              style: function (feature) {
                  var size = feature.get('features').length;
                  var style;
                  if (size > 0) {
                      var f = feature.get('features')[0];
                      if (f.get("bklayerStyleObject") != null && f.get("bklayerStyleFunction") != null) {
                          style = f.get("bklayerStyleObject")[f.get("bklayerStyleFunction")](size);
                      }
                  }
                  return style;
              },
              visible: config.visible
          });
      } else if (config.bklayerType.toLowerCase() == "imgvectorlayer") {
          config.bklayerType = "vectorlayer";
          layer = new ol.layer.Vector({
              source: new ol.source.Vector({ wrapX: false }),
              style: function (feature) {
                  var style;
                  var f = feature;
                  if (f.get("bklayerStyleObject") != null && f.get("bklayerStyleFunction") != null) {
                      style = f.get("bklayerStyleObject")[f.get("bklayerStyleFunction")](feature, false, layer);
                  }

                  return style;
              },
              visible: config.visible
          });
      } else if (config.bklayerType.toLowerCase() == "siweilayer") {
          var tiledUtils = new TiledUtils();
          var tileGrid = tiledUtils.tileGrid_siwei();
          // var mapurl = config.bklayerUrl+"?product_id=101&service=WMTS&request=GetTile&version=1.0.0&LAYER=&TileMatrix={z}&TileRow={y}&TileCol={x}&style=default&format=image/png&mgt_token=d2ca3f37cd1aa15783d3639865315c5d";//&tileMatrixSet="+config.wmtstileMatrixSet+
          var mapurl = config.bklayerUrl + "&zoom={z}&row={y}&col={x}&format=image/png";
          var tileArcGISXYZ = new ol.source.XYZ({
              tileGrid: tileGrid,
              maxZoom: 17,
              projection: tiledUtils.projection(),
              url: mapurl
          });
          layer = new ol.layer.Tile({
              source: tileArcGISXYZ,
              visible: config.visible
          });
      } else if (config.bklayerType.toLowerCase() == "offline_arctilelayer") {
          config.bklayerType = "offline_tilelayer";
          var tiledUtils = new TiledUtils();
          layer = new ol.layer.Tile({
              source: new ol.source.XYZ({
                  projection: tiledUtils.projection(),
                  crossOrigin: 'anonymous',
                  tileGrid: tiledUtils.offline_tileGrid(),
                  tileUrlFunction: function (coordinate) {
                      var x = 'C' + tiledUtils.zeroFill(coordinate[1], 8, 16);
                      var y = 'R' + tiledUtils.zeroFill(-coordinate[2] - 1, 8, 16);
                      var z = 'L' + tiledUtils.zeroFill(coordinate[0], 2, 10);
                      return config.rootpath + '/swcapp/mapdata/' + config.bklayerQb + '/' + z + '/' + y + '/' + x + '.bklayer';
                  }
              }),
              visible: config.visible
          });

      } else if (config.bklayerType.toLowerCase() == "offline_tilelayer") {
          var tiledUtils = new TiledUtils();
          var tileUrl = config.rootpath + '/' + "{z}/{x}/{y}.bklayer";
          layer = new ol.layer.Tile({
              source: new ol.source.XYZ({
                  projection: tiledUtils.projection(),
                  crossOrigin: 'anonymous',
                  tileGrid: tiledUtils.offline_tileGrid(),
                  url: tileUrl
              }),
              visible: config.visible
          });
      } else if (config.bklayerType.toLowerCase() == "offline_geotilelayer") {
          config.bklayerType = "offline_tilelayer";
          var tiledUtils = new TiledUtils();
          var tileUrl = config.rootpath;
          var tileId = "201901";
          layer = new ol.layer.Tile({
              source: new ol.source.XYZ({
                  projection: tiledUtils.projection(),
                  crossOrigin: 'anonymous',
                  tileGrid: tiledUtils.offline_tileGrid(),
                  tileUrlFunction: function (tileCoord) {
                      return tileCoord.toString();
                  },
                  tileLoadFunction: function (tile, url) {
                      try {
                          var params = {
                              url: url,
                              tileUrl: tileUrl,
                              tileId: tileId
                          };
                          console.info(url);
                          $.ajax({
                              type: "POST",
                              url: "/lxdt/lxdtshow",
                              data: params,
                              success: function (data) {
                                  tile.getImage().src = data;
                                  // console.info(data);
                              }
                          });
                          // if(plus.MapUtil != undefined){
                          //     tile.getImage().src=plus.MapUtil.fetchTile(params);
                          // }
                      } catch (e) {

                      }
                  }
              }),
              visible: config.visible
          });
      } else if (config.bklayerType.toLowerCase() == "tianditu") {
        var urls = [];
        for (var i = 0; i < 5; i++) {
            var url = "https://t" + i + ".tianditu.gov.cn/" + config.bklayerTiandituType + "/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=" + config.bklayerTiandituType.split("_")[0] + `&STYLE=default&TILEMATRIXSET=c&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=${window.serverConfigs.tiandituKey ? window.serverConfigs.tiandituKey : '55741f2ad97e4af08eee8576d7ba9b39'}`
            urls.push(url)
        }
        layer = new ol.layer.Tile({
            source: new ol.source.XYZ({
                crossOrigin: 'anonymous',
                projection: ol.proj.get('EPSG:4326'),
                urls: urls
            }),
            visible: config.visible
        })
    } else if (config.bklayerType.toLowerCase() == "bingmaps") {
          layer = new ol.layer.Tile({
              visible: config.visible,
              preload: Infinity,
              source: new ol.source.BingMaps({
                crossOrigin: 'anonymous',
                key: "ApTJzdkyN1DdFKkRAE6QIDtzihNaf6IWJsT-nQ_2eMoO4PN__0Tzhl2-WgJtXFSp",
                imagerySet: 'Aerial'
              })
          })
      } else if (config.bklayerType.toLowerCase() == "baidu") {
          /*            var urls = [];
                      for (var i = 0; i < 1; i++) {
                          urls.push("http://t" + 2 + ".tianditu.gov.cn/img_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TileMatrix={z}&TileRow={y}&TileCol={x}&tk=83e186f3265145e0f917d465a1e07d1d")
                      }*/
          layer = new ol.layer.Tile({
              source: new ol.source.XYZ({
                  projection: ol.proj.get('EPSG:4326'),
                  url: "http://t{3-6}.tianditu.gov.cn/DataServer?T=img_c&X={x}&Y={y}&L={z}&tk=82378f09186a5156532f745084636f5b"
              }),
              visible: config.visible
          })
      } else if (config.bklayerType.toLowerCase() == "gaode") {
        layer = new ol.layer.Tile({
          source: new ol.source.XYZ({
              crossOrigin: 'anonymous',
              projection: gcj02Mecator,
              url: `http://wprd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=${config.bklayerGaodeStyle}&x={x}&y={y}&z={z}`,
              wrapX: false
          }),
          visible: config.visible
        })
      } else if (config.bklayerType.toLowerCase() == "mercator_tms") {
        layer = new ol.layer.Tile({
            extent: config.extent,
            source: new ol.source.XYZ({
                projection: ol.proj.get('EPSG:3857'),
                crossOrigin: 'anonymous',
                url: config.bklayerUrl + '/{z}/{x}/{-y}.png',
            }),
            visible: config.visible
        });
      } else if (config.bklayerType.toLowerCase() == "mercator_xyz") {
        layer = new ol.layer.Tile({
            extent: config.extent,
            source: new ol.source.XYZ({
                projection: ol.proj.get('EPSG:3857'),
                crossOrigin: 'anonymous',
                url: config.bklayerUrl + '/{z}/{x}/{y}.png',
            }),
            visible: config.visible
        });
      } else if (config.bklayerType.toLowerCase() == "supermapwmts") {
            const resolutions = new Array(19);
            const matrixIds = new Array(19);
            const size=config.size;
            for (let z = 0; z < 19; ++z) {
            // generate resolutions and matrixIds arrays for this WMTS
            resolutions[z] =  1.4062500000022087 / Math.pow(2, z);
            matrixIds[z] = z;
            }
            console.log(resolutions)
        layer = new ol.layer.Tile({
            source: new ol.source.WMTS({
                crossOrigin: 'anonymous',
                url: config.bklayerUrl,
                // url: 'http://10.243.45.80:8090/iserver/services/map-ugcv5-HeBeiTerrainV2/wmts100',
                // layer: config.layers,
                // style: config.bkstyle || "default",
                matrixSet: config.matrixSet,
                layer: config.layers,
                style: config.bkstyle || "default", 
                //TILEMATRIXSET: 'Custom_HeBeiTerrainV2',
                format: "image/png",
                projection: ol.proj.get('EPSG:4326'),
                wrapX: true,
                tileGrid: new ol.tilegrid.WMTS({
                    origin: ol.extent.getTopLeft(size),
                    extent: config.extent,
                    resolutions:resolutions,
                    matrixIds: matrixIds
                })
            }),
            visible: config.visible
        });
    } else if (config.bklayerType.toLowerCase() == "supermapwmtstdt") {
      //创建"EPSG:4490"的Projection实例，Openlayers将可以从Proj4js中获取转换函数。

      var projection = new ol.proj.Projection({
          code: 'EPSG:4490',
          units: 'degrees',
          axisOrientation: 'neu'
      });
      ol.proj.addProjection(projection);
      projection.setExtent([-180, -90, 180, 90]);
      projection.setWorldExtent([-180, -90, 180, 90]);
      projection.getMetersPerUnit = function () {
          return 2 * Math.PI * 6378137 / 360;
      };
      ol.proj.addCoordinateTransforms("EPSG:4326", "EPSG:4490", function (coordinate) {
          return proj4("EPSG:4490", "EPSG:4326", coordinate);
      },
          function (coordinate) {
              return proj4("ERSG:4490", "EPSG:4326", coordinate);
          }
      );

      let projectionExtent = projection.getExtent();
      let size = ol.extent.getWidth(projectionExtent) / 256; //size就是一个像素代表的经纬度
      let matrixIds = [];

      let resolutions = [];
      for (let z = 0; z < 20; ++z) {
          resolutions[z] = size / Math.pow(2, z);
          matrixIds[z] = z;
      }
    layer = new ol.layer.Tile({
        source: new ol.source.WMTS({
            crossOrigin: 'anonymous',
            url: config.bklayerUrl+'?k=BPAFgxSWrHkDo05+cZFXmA==',
            layer: config.layers,
            style: config.bkstyle || "default",
            matrixSet: config.matrixSet,
            format: "tiles",
            projection: projection ,
            tileGrid: new ol.tilegrid.WMTS({
                origin: [-180, 90],
                resolutions: resolutions,
                matrixIds: matrixIds
            })
        }),
        visible: config.visible
    });
} else if (config.bklayerType.toLowerCase() == "tilearcgisrestlayer") {
          var url = null;
          layer = new ol.layer.Tile({
              source: new ol.source.TileArcGISRest({
                  crossOrigin: 'anonymous',
                  url: config.bklayerUrl
              }),
              visible: config.visible,
              opacity: config.opacity ? config.opacity : 1,
              legendDic:config.legendDic||''
          });
      } else if (config.bklayerType.toLowerCase() == "imagearcgisrestlayer") {
          var url = null;

          var source_options = {
              url: config.bklayerUrl,
              crossOrigin: 'anonymous',
              projection: ol.proj.get('EPSG:4326')
          }

          if (config.imageParameters && config.imageParameters.layerIds) {
              Ext.apply(source_options, {
                  params: {
                      layers: "show: " + config.imageParameters.layerIds.join(",")
                  }
              })
          }

          layer = new ol.layer.Image({
              source: new ol.source.ImageArcGISRest(source_options),
              visible: config.visible,
              opacity: config.opacity ? config.opacity : 1,
              legendDic: config.legendDic || ''
          });
      } else if (config.bklayerType.toLowerCase() == "ogcwmts") {
          layer = new ol.layer.Tile({
              source: new ol.source.WMTS({
                  // crossOrigin: 'anonymous',
                  url: config.bklayerUrl,
                  layer: config.layers,
                  projection: ol.proj.get('EPSG:4326'),
                  style: config.bkstyle || "default",
                  matrixSet: "EPSG:4326",
                  format: "tiles",
                  wrapX: true,
                  tileGrid: new ol.tilegrid.WMTS({
                      origin: [-180, 90],
                      resolutions: [1.40625, 0.703125, 0.3515625, 0.17578125, 0.087890625, 0.0439453125, 0.02197265625, 0.010986328125, 0.0054931640625, 0.00274658203125, 0.001373291015625, 0.0006866455078125, 0.00034332275390625, 0.000171661376953125, 0.0000858306884765625, 0.00004291534423828125, 0.000021457672119140625, 0.000010728836059570312, 0.000005364418029785156, 0.000002682209014892578, 0.000001341104507446289],
                      matrixIds: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
                  })
              }),
              visible: config.visible
          });
      } else if (config.bklayerType.toLowerCase() == "geoserverwms") {
          if (config.singleTile) {
              layer = new ol.layer.Image({
                  visible: config.visible,
                  source: new ol.source.ImageWMS({
                      url: config.bklayerUrl,
                      crossOrigin: 'anonymous',
                      extent: config.extent,
                      //   serverType: "geoserver",
                      params: {
                          'FORMAT': 'image/png',
                          'VERSION': '1.1.1',
                          STYLES: config.bkstyle,
                          //random:uuid,
                          LAYERS: config.bklayers,
                          exceptions: 'application/vnd.ogc.se_inimage',
                          tilesOrigin: config.tilesOrigin,
                          env: config.env,
                          CQL_FILTER: config.CQL_FILTER
                      }
                  })
              });
          } else {
              layer = new ol.layer.Tile({
                  visible: config.visible,
                  source: new ol.source.TileWMS({
                      url: config.bklayerUrl,
                      crossOrigin: 'anonymous',
                      extent: config.extent,
                      params: {
                          'FORMAT': 'image/png',
                          'VERSION': '1.1.1',
                          tiled: true,
                          STYLES: config.bkstyle,
                          random: uuid,//
                          LAYERS: config.bklayers,
                          exceptions: 'application/vnd.ogc.se_inimage',
                          tilesOrigin: config.tilesOrigin,
                          env: config.env,
                          CQL_FILTER: config.CQL_FILTER
                      }
                  })
              });
          }
      } else if (config.bklayerType.toLowerCase() == "googlelayer") {
          var url = 'https://gac-geo.googlecnapps.cn/maps/vt?lyrs=s&x={x}&y={y}&z={z}'
          if (config.bklayerGoogleType == "img") {
            // 谷歌卫星
              url = 'https://gac-geo.googlecnapps.cn/maps/vt?lyrs=s&x={x}&y={y}&z={z}'
          } else if (config.bklayerGoogleType == "imgbz") {
            // 道路
              url = 'https://gac-geo.googlecnapps.cn/maps/vt?lyrs=h&x={x}&y={y}&z={z}'
          } else if (config.bklayerGoogleType == "r") {
            // 矢量
              url = 'https://gac-geo.googlecnapps.cn/maps/vt?lyrs=r&x={x}&y={y}&z={z}'
          }
          layer = new ol.layer.Tile({
              source: new ol.source.XYZ({
                  projection: config.bklayerGoogleType == "img"?ol.proj.get('EPSG:3857'):gcj02Mecator,
                  crossOrigin: 'anonymous',
                  url: url
              }),
              visible: config.visible
          });
      } else if (config.bklayerType.toLowerCase() == "arctilelayer") {
          var tiledUtils = new TiledUtils();
          var tileGrid = tiledUtils.tileGrid();
          if (config.arcGisTileGridType == "T400") {
              tileGrid = tiledUtils.tileGrid400();
          }
          var tileArcGISXYZ = new ol.source.XYZ({
              tileGrid: tileGrid,
              projection: tiledUtils.projection(),
              // crossOrigin: 'anonymous',
              url: config.bklayerUrl + "/tile/{z}/{y}/{x}"
          });
          layer = new ol.layer.Tile({
              source: tileArcGISXYZ,
              visible: config.visible
          });
      } else if (config.bklayerType.toLowerCase() == "heatmap") {
          var source_ = null;
          if (config.source) {
              source_ = initConfig.source;
          } else {
              source_ = new ol.source.Vector({});
          }

          var radius_ = config.radius ? config.radius : 15,
              blur_ = config.blur ? config.blur : 15;

          var options_ = {
              source: source_,
              radius: radius_,
              blur: blur_,
              weight: function (feature) {
                  var name = feature.get('magn');
                  var magnitude = parseFloat(name);
                  return magnitude;
              },
              visible: config.visible
          }

          layer = new ol.layer.Heatmap(options_);
      } else if (config.bklayerType.toLowerCase() == "xyz") {
        let projection = ol.proj.get("EPSG:4326");
        let projectionExtent = projection.getExtent();
        let width = ol.extent.getWidth(projectionExtent);
        let resolutions = [];
        let matrixIds = [];
        for (let z = 0; z < 18; z++) {
            resolutions[z] = width / (256 * Math.pow(2, z + 1));
            matrixIds[z] = z;
        }
        let wmtsTileGrid = new ol.tilegrid.WMTS({
            origin: ol.extent.getTopLeft(projectionExtent),
            resolutions: resolutions,
            matrixIds: matrixIds
        });
        layer = new ol.layer.Tile({
            source: new ol.source.XYZ({
                crossOrigin: 'anonymous',
                url: config.bklayerUrl,
                projection: 'EPSG:4326',
                wrapX: true,
                tileGrid: wmtsTileGrid
            }),
            visible: config.visible
        });
      }

      if (layer != null) {
          layer.set("bklayerType", config.bklayerType);
          if (config.bklayerId) {
              layer.set("bklayerId", config.bklayerId);
          }
          if (config.bklayerBzCode) {
              layer.set("bklayerBzCode", config.bklayerBzCode);
          }
          if (config.bklayerName) {
              layer.set("bklayerName", config.bklayerName);
          }
          if (config.bklayerDesc) {
              layer.set("bklayerDesc", config.bklayerDesc);
          }
          if (config.bklayerDesc) {
              layer.set("bklayerDesc", config.bklayerDesc);
          }
          if (config.bklayerGroupId) {
              layer.set("bklayerGroupId", config.bklayerGroupId);
          }
          if (config.maxResolution) {
              layer.setMaxResolution(config.maxResolution);
          }
          if (config.minResolution) {
              layer.setMinResolution(config.minResolution);
          }
          layer.set("bklayerSn", config.bklayerSn);
          layer.setZIndex(config.bklayerSn);
      }
      return layer;
  },
  defaultClusterStyle: function () {

  }

}
